#include<iostream>
#include<cstdio>
using namespace std;
string s;
int n,h[100010],tt=0;
long long a[5];
struct nh
{
	int i,q,w,e,r,t,nt;
}ha[100010];
bool chek(int i,string s)
{
	if(!(s[0]>='0'&&s[0]<='9')||(s[0]=='0'&&s[1]>='0'&&s[1]<='9'))return 0;
	bool flag=1;
	int f=0,g=0,kk=0;
	a[0]=a[1]=a[2]=a[3]=a[4]=0;
	for(;i<s.size();i++)
	{
		if(!(s[i]>='0'&&s[i]<='9')&&!(s[i+1]>='0'&&s[i+1]<='9'))flag=0;
		if(s[i]=='.')
		{
			f++;
			if(s[i+1]=='0'&&s[i+2]>='0'&&s[i+2]<='9')flag=0;
		}
		else if(s[i]==':')
		{
			g++;
			if(s[i+1]=='0'&&s[i+2]>='0'&&s[i+2]<='9')flag=0;
		}
		else
		{
			a[f+g]=a[f+g]*10+s[i]-'0';
			if(a[f+g]>100000)return 0;
		}
		if(f!=3&&g==1)flag=0;
	}
	if(s[s.size()-1]=='.'||s[s.size()-1]==':'||a[0]>255||a[1]>255||a[2]>255||a[3]>255||a[4]>65535||f!=3||g!=1)flag=0;
	return flag;
}
void add(int i)
{
	int o=(a[0]+a[1]+a[2]+a[3]+a[4])%100007;
	int p=o;
	ha[++tt].i=i;
	ha[tt].q=a[0];
	ha[tt].w=a[1];
	ha[tt].e=a[2];
	ha[tt].r=a[3];
	ha[tt].t=a[4];
	ha[tt].nt=h[p];
	h[p]=tt;
}
int ff()
{
	int o=(a[0]+a[1]+a[2]+a[3]+a[4])%100007;
	int p=o;
	for(int i=h[p];i;i=ha[i].nt)
		if(ha[i].q==a[0]&&ha[i].w==a[1]&&ha[i].e==a[2]&&ha[i].r==a[3]&&ha[i].t==a[4])return ha[i].i;
	return 0;
}
int main()
{
	freopen("network.in","r",stdin); 
	freopen("network.out","w",stdout);
	for(int i=0;i<100000;i++)h[i]=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		if(s=="Server")
		{
			cin>>s;
			if(!chek(0,s))
			{
				cout<<"ERR\n";
				continue;
			}
			int a1=ff();
			if(a1!=0)
			{
				cout<<"FAIL\n";
				continue;
			}
			add(i+1);
			cout<<"OK\n";
		}
		else
		{
			cin>>s;
			if(!chek(0,s))
			{
				cout<<"ERR\n";
				continue;
			}
			int a1=ff();
			if(a1!=0)
			{
				cout<<a1<<"\n";
				continue;
			}
			cout<<"FAIL\n";
		}
	}
	return 0;
}
